/* eslint-disable no-undef,no-unused-vars,jsx-a11y/href-no-hash,jsx-a11y/img-has-alt,jsx-a11y/img-has-alt,jsx-a11y/no-marquee,function-paren-newline */
// eslint-disable-next-line jsx-a11y/no-marquee
import React, { Component } from 'react';
import { Menu, message, Icon } from 'antd';
import styles from './ToolBar.less';
import * as config from '../../../utils/config';
import * as commonFunc from '../commonFunc';
import AffixMenu from '../../../routes/common/AffixMenu';

const { SubMenu } = Menu;

class ToolBarComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      componentName: props.componentName,
      sTabId: props.app.currentPane.key, /* 记录每个标签的Id */
      barContent: [], /* 显示工具栏 */
      gdsconfigformslave: [],
      gdsjurisdiction: [],
      gdsformconst: [],
    };
  }

  componentWillMount() {
    const { masterConfig, gdsformconst, gdsjurisdiction } = this.props;
    const btnData = JSON.parse(JSON.stringify(config.btnData));
    gdsjurisdiction.forEach((child) => {
      const index = btnData.findIndex(item => (item.sName === child.sAction));
      if (index > 0) {
        btnData.splice(index, 1);
      }
    });
    const { gdsconfigformslave } = masterConfig;
    /* 复制到菜单全部配置 */
    const copyToMenu = commonFunc.getConfigCopyTo(gdsconfigformslave, 'BtnCopyTo');
    /* 复制从菜单全部配置 */
    const copyFromMenu = commonFunc.getConfigCopyTo(gdsconfigformslave, '3copyForm');
    /* 上查菜单全部配置 */
    const searchUpMenu = commonFunc.getConfigCopyTo(gdsconfigformslave, '4searchUp');
    /* 下查菜单全部配置 */
    const searchDownMenu = commonFunc.getConfigCopyTo(gdsconfigformslave, '5searchDown');
    /* 复制到菜单下拉项配置 */
    const copyToMenuSelect = commonFunc.getConfigCopyToSelect(gdsconfigformslave, 'BtnCopyTo');
    /* 复制从菜单下拉项配置 */
    const copyFromMenuSelect = commonFunc.getConfigCopyToSelect(gdsconfigformslave, '3copyForm');
    /* 上查菜单下拉项配置 */
    const searchUpMenuSelect = commonFunc.getConfigCopyToSelect(gdsconfigformslave, '4searchUp');
    /* 下查菜单下拉项配置 */
    const searchDownMenuSelect = commonFunc.getConfigCopyToSelect(gdsconfigformslave, '5searchDown');
    const data = JSON.parse(JSON.stringify(this.props.btnData));
    const barContent = [];
    const button = data.filter(item => item.sName.indexOf('.') === -1);
    const childButton = data.filter(item => item.sName.indexOf('.') > -1);
    button.forEach((btn) => {
      const btnConfig = commonFunc.getConfig('control', btn.sName, gdsconfigformslave, gdsformconst, gdsjurisdiction, btn.showName);
      if (btn.sName === 'BtnCopyTo' || btn.sName === 'BtnUpCheck' || btn.sName === 'BtnDownCheck' || btn.sName === 'BtnCopyFrom') {
        if (btnConfig.bVisible) {
          const btnChild = [];
          let selectFlag = 0;/* 如果只存在一个菜单下拉项则不进行添加 */
          if (btn.sName === 'BtnCopyTo') {
            if (copyToMenuSelect.length > 1) {
              copyToMenuSelect.forEach((item) => {
                btnChild.push(
                  <Menu.Item
                    key={item.sControlName}
                    data-sactiveid={item.sActiveId}
                    data-cfig={copyToMenu.filter(child => child.sControlName.indexOf(item.sControlName.substr(item.sControlName.indexOf('.') + 1)) > 0)}
                  >
                    {item.showName}
                  </Menu.Item>);
              });
            } else {
              selectFlag = 1;
              console.log('menuChild', copyToMenu, menuChild);
              const menuChild = copyToMenu.filter(child => child.sControlName.indexOf(copyToMenuSelect[0].sControlName.substr(copyToMenuSelect[0].sControlName.indexOf('.') + 1)) > 0);

              if (this.props.selectStatus) {
                barContent.push(
                  <Menu.Item
                    key={btn.sName}
                    data-sactiveid={menuChild.length > 0 ? menuChild[0].sActiveId : ''}
                    data-cfig={menuChild}
                    disabled
                  >{btnConfig.showName}
                  </Menu.Item>);
              } else {
                barContent.push(
                  <Menu.Item
                    key={btn.sName}
                    data-sactiveid={menuChild.length > 0 ? menuChild[0].sActiveId : ''}
                    data-cfig={menuChild}
                  >{btnConfig.showName}
                  </Menu.Item>);
              }
            }
          } else if (btn.sName === 'BtnCopyFrom') {
            if (copyFromMenuSelect.length > 1) {
              copyFromMenuSelect.forEach((item) => {
                btnChild.push(
                  <Menu.Item
                    key={item.sId}
                    data-sactiveid={item.sActiveId}
                    data-cfig={copyFromMenu.filter(child => child.sControlName.indexOf(item.sControlName.substr(item.sControlName.indexOf('.') + 1)) > 0)}
                  >{item.showName}
                  </Menu.Item>);
              });
            } else {
              selectFlag = 1;
              const menuChild = copyFromMenu.filter(child => child.sControlName.indexOf(copyFromMenuSelect[0].sControlName.substr(copyFromMenuSelect[0].sControlName.indexOf('_') + 1)) > 0);
              barContent.push(
                <Menu.Item
                  key={btn.sName}
                  data-sactiveid={menuChild.length > 0 ? menuChild[0].sActiveId : ''}
                  data-cfig={menuChild}
                ><Icon type="folder-open" />{btnConfig.showName}
                </Menu.Item>);
            }
          } else if (btn.sName === 'BtnUpCheck') {
            if (searchUpMenuSelect.length > 1) {
              searchUpMenuSelect.forEach((item) => {
                btnChild.push(
                  <Menu.Item
                    key={item.sId}
                    data-sactiveid={item.sActiveId}
                    data-cfig={searchUpMenu.filter(child => child.sControlName.indexOf(item.sControlName.substr(item.sControlName.indexOf('_') + 1)) > 0)}
                  ><Icon type="menu-fold" />{item.showName}
                  </Menu.Item>);
              });
            } else {
              selectFlag = 1;
              const menuChild = searchUpMenu.filter(child => child.sControlName.indexOf(searchUpMenuSelect[0].sControlName.substr(searchUpMenuSelect[0].sControlName.indexOf('_') + 1)) > 0);
              barContent.push(
                <Menu.Item
                  key={btn.sName}
                  data-sactiveid={menuChild.length > 0 ? menuChild[0].sActiveId : ''}
                  data-cfig={searchUpMenu.filter(child => child.sControlName.indexOf(searchUpMenuSelect[0].sControlName.substr(searchUpMenuSelect[0].sControlName.indexOf('_') + 1)) > 0)}
                ><Icon type="menu-fold" />{btnConfig.showName}
                </Menu.Item>);
            }
          } else if (btn.sName === 'BtnDownCheck') {
            if (searchDownMenuSelect.length > 1) {
              searchDownMenuSelect.forEach((item) => {
                btnChild.push(
                  <Menu.Item
                    key={item.sId}
                    data-sactiveid={item.sActiveId}
                    data-cfig={searchDownMenu.filter(child => child.sControlName.indexOf(item.sControlName.substr(item.sControlName.indexOf('_') + 1)) > 0)}
                  >{item.showName}
                  </Menu.Item>);
              });
            } else {
              selectFlag = 1;
              const menuChild = searchDownMenu.filter(child => child.sControlName.indexOf(searchDownMenuSelect[0].sControlName.substr(searchDownMenuSelect[0].sControlName.indexOf('_') + 1)) > 0);
              barContent.push(
                <Menu.Item
                  key={btn.sName}
                  data-sactiveid={menuChild.length > 0 ? menuChild[0].sActiveId : ''}
                  data-cfig={searchDownMenu.filter(child => child.sControlName.indexOf(searchDownMenuSelect[0].sControlName.substr(searchDownMenuSelect[0].sControlName.indexOf('_') + 1)) > 0)}
                ><Icon type="menu-unfold" />{btnConfig.showName}
                </Menu.Item>);
            }
          }
          if (selectFlag === 0) {
            if (btn.sName === 'BtnCopyTo') {
              if (this.props.selectStatus) {
                barContent.push(
                  <SubMenu
                    key={btn.sName}
                    className={styles.toolBarSub}
                    title={<span><Icon type="copy" /><span>{btnConfig.showName}</span><Icon type="down" theme="outlined" /></span>}
                    disabled
                  >{btnChild}
                  </SubMenu>);
              } else {
                barContent.push(
                  <SubMenu
                    key={btn.sName}
                    className={styles.toolBarSub}
                    title={<span><Icon type="copy" /><span>{btnConfig.showName}</span><Icon type="down" theme="outlined" /></span>}
                  >{btnChild}
                  </SubMenu>);
              }
            } else {
              barContent.push(
                <SubMenu
                  key={btn.sName}
                  className={styles.toolBarSub}
                  title={<span><Icon type="menu-unfold" /><span>{btnConfig.showName}</span><Icon type="down" theme="outlined" /></span>}
                >{btnChild}
                </SubMenu>);
            }
          }
        }
      } else {
        const child = childButton.filter(item => item.sName.indexOf(`${btn.sName}.`) > -1);
        if (btnConfig.bVisible) {
          if (btn.sName === 'BtnPrior' || btn.sName === 'BtnNext' || btn.sName === 'BtnFirst' || btn.sName === 'BtnLast') {
            if (this.props.sId !== undefined && this.props.sId !== '') {
              if (child.length === 0) {
                if (btn.sName === 'BtnPrior') {
                  barContent.push(
                    <Menu.Item
                      key={btn.sName}
                    ><Icon type="left-square-o" />{btnConfig.showName}
                    </Menu.Item>);
                } else if (btn.sName === 'BtnFirst') {
                  barContent.push(
                    <Menu.Item
                      key={btn.sName}
                    ><Icon type="up-square-o" />{btnConfig.showName}
                    </Menu.Item>);
                } else if (btn.sName === 'BtnLast') {
                  barContent.push(
                    <Menu.Item
                      key={btn.sName}
                    ><Icon type="down-square-o" />{btnConfig.showName}
                    </Menu.Item>);
                } else {
                  barContent.push(
                    <Menu.Item
                      key={btn.sName}
                    ><Icon type="right-square-o" />{btnConfig.showName}
                    </Menu.Item>);
                }
              } else {
                const btnChild = [];
                child.forEach((item) => {
                  const childConfig = commonFunc.getConfig('control', item.sName, gdsconfigformslave, gdsformconst, gdsjurisdiction, item.showName);
                  if (childConfig.bVisible) {
                    btnChild.push(
                      <Menu.Item
                        key={item.sName}
                      >{childConfig.showName}
                      </Menu.Item>);
                  }
                });
                barContent.push(
                  <SubMenu
                    key={btn.sName}
                    title={btnConfig.showName}
                    className={styles.toolBarSub}
                  >{btnChild}
                  </SubMenu>);
              }
            } else if (this.props.sId !== undefined && this.props.sId === '') {
              if (child.length === 0) {
                barContent.push(
                  <Menu.Item
                    key={btn.sName}
                    disabled
                  > {btnConfig.showName}
                  </Menu.Item>);
              } else {
                const btnChild = [];
                child.forEach((item) => {
                  const childConfig = commonFunc.getConfig('control', item.sName, gdsconfigformslave, gdsformconst, gdsjurisdiction, item.showName);
                  if (childConfig.bVisible) {
                    btnChild.push(
                      <Menu.Item
                        key={item.sName}
                      >{childConfig.showName}
                      </Menu.Item>);
                  }
                });
                barContent.push(
                  <SubMenu
                    key={btn.sName}
                    title={btnConfig.showName}
                    className={styles.toolBarSub}
                  >{btnChild}
                  </SubMenu>);
              }
            }
          } else if (child.length === 0) {
            if (btn.sName === 'BtnRefresh') {
              barContent.push(
                <Menu.Item
                  key={btn.sName}
                ><Icon type="reload" />{btnConfig.showName}
                </Menu.Item>);
            } else if (btn.sName === 'BtnAdd') {
              barContent.push(
                <Menu.Item
                  key={btn.sName}
                ><Icon type="plus" />{btnConfig.showName}
                </Menu.Item>);
            } else if (btn.sName === 'BtnDel') {
              barContent.push(
                <Menu.Item
                  key={btn.sName}
                ><Icon type="delete" />{btnConfig.showName}
                </Menu.Item>);
            } else if (btn.sName === 'BtnUpd') {
              barContent.push(
                <Menu.Item
                  key={btn.sName}
                ><Icon type="edit" />{btnConfig.showName}
                </Menu.Item>);
            } else if (btn.sName === 'BtnSave') {
              barContent.push(
                <Menu.Item
                  key={btn.sName}
                ><Icon type="save" />{btnConfig.showName}
                </Menu.Item>);
            } else if (btn.sName === 'BtnCancel') {
              barContent.push(
                <Menu.Item
                  key={btn.sName}
                ><Icon type="close" />{btnConfig.showName}
                </Menu.Item>);
            } else if (btn.sName === 'BtnExamine') {
              barContent.push(
                <Menu.Item
                  key={btn.sName}
                ><Icon type="check" />{btnConfig.showName}
                </Menu.Item>);
            } else if (btn.sName === 'BtnCancelExamine') {
              barContent.push(
                <Menu.Item
                  key={btn.sName}
                ><Icon type="rollback" />{btnConfig.showName}
                </Menu.Item>);
            } else if (btn.sName === 'BtnPrint') {
              barContent.push(
                <Menu.Item
                  key={btn.sName}
                ><Icon type="printer" />{btnConfig.showName}
                </Menu.Item>);
            } else {
              barContent.push(
                <Menu.Item
                  key={btn.sName}
                ><Icon type="file-excel" />{btnConfig.showName}
                </Menu.Item>);
            }
          } else {
            const btnChild = [];
            child.forEach((item) => {
              const childConfig = commonFunc.getConfig('control', item.sName, gdsconfigformslave, gdsformconst, gdsjurisdiction, item.showName);
              if (childConfig.bVisible) {
                btnChild.push(
                  <Menu.Item
                    key={item.sName}
                  >{childConfig.showName}
                  </Menu.Item>);
              }
            });
            barContent.push(
              <SubMenu
                key={btn.sName}
                title={<span><Icon type="bars" /><span>{btn.showName}</span><Icon type="down" theme="outlined" /></span>}
                className={styles.toolBarSub}
              >{btnChild}
              </SubMenu>);
          }
        }
      }
    });
    this.setState({
      barContent, gdsconfigformslave, gdsjurisdiction, gdsformconst, copyToMenu, copyToMenuSelect,
    });
  }

  componentWillReceiveProps(nextProps) {
    const { gdsconfigformslave, gdsjurisdiction, gdsformconst } = this.state;
    const btnData = JSON.parse(JSON.stringify(nextProps.btnData));
    gdsjurisdiction.forEach((child) => {
      const index = btnData.findIndex(item => (item.sName === child.sAction));
      if (index > 0) {
        btnData.splice(index, 1);
      }
    });
    const btnDataChild = nextProps.btnDataChild === undefined ? [] : nextProps.btnDataChild;
    const btnDataAll = [...btnData, ...btnDataChild];
    const btnDataAllShow = commonFunc.getBtnShowName(btnDataAll, gdsconfigformslave);
    const data = JSON.parse(JSON.stringify(btnDataAllShow));
    const button = data.filter(item => item.sName.indexOf('.') === -1);
    const childButton = data.filter(item => item.sName.indexOf('.') > -1);
    const { barContent } = this.state;
    if (nextProps.disabled !== undefined) {
      if (nextProps.disabled) {
        /* 查看状态 */
        barContent.forEach((child, i) => {
          if (child.key === 'BtnSave' || child.key === 'BtnCancel') {
            child = {
              ...child,
              props: { ...child.props, disabled: true },
            };
            barContent[i] = { ...child };
          } else {
            child = {
              ...child,
              props: { ...child.props, disabled: false },
            };
            barContent[i] = { ...child };
          }
        });
        if (nextProps.bCheck !== undefined) {
          if (nextProps.bCheck) {
            /* 审核按钮置灰，消审高亮 */
            const indexExam = barContent.findIndex(item => item.key === 'BtnExamine');
            const examineData = button.filter(item => item.sName === 'BtnExamine')[0];
            barContent[indexExam] = (
              <Menu.Item
                key={examineData.sName}
                disabled
              ><Icon type="check" />{examineData.showName}
              </Menu.Item>);
            const indexCancel = barContent.findIndex(item => item.key === 'BtnCancelExamine');
            const cancelExamineData = button.filter(item => item.sName === 'BtnCancelExamine')[0];
            barContent[indexCancel] = (
              <Menu.Item
                key={cancelExamineData.sName}
              ><Icon type="rollback" />{cancelExamineData.showName}
              </Menu.Item>);
            /* 暂时隐藏 */
            // /* 复制到按钮 */
            // const indexCopy = barContent.findIndex(item => item.key === 'BtnCopyTo');
            // const barContentData = barContent.filter(item => item.key === 'BtnCopyTo')[0];
            // if (barContentData !== undefined) {
            //   const children = barContentData.props.children !== undefined && Array.isArray(barContentData.props.children) ? barContentData.props.children : '';
            //   const copyData = button.filter(item => item.sName === 'BtnCopyTo')[0];
            //   if (children !== '') {
            //     barContent[indexCopy] = (
            //       <SubMenu
            //         key={copyData.sName}
            //         title={<span><Icon type="copy" /><span>{copyData.showName}</span><Icon type="down" theme="outlined" /></span>}
            //         className={styles.toolBarSub}
            //       >
            //         {children}
            //       </SubMenu>);
            //   } else {
            //     const { copyToMenu, copyToMenuSelect } = this.state;
            //     const menuChild = copyToMenu.filter(child => child.sControlName.indexOf(copyToMenuSelect[0].sControlName.substr(copyToMenuSelect[0].sControlName.indexOf('_') + 1)) > 0);
            //     barContent[indexCopy] = (
            //       <Menu.Item
            //         key={copyData.sName}
            //         data-sactiveid={menuChild.length > 0 ? menuChild[0].sActiveId : ''}
            //         data-cfig={menuChild}
            //       ><Icon type="copy" />{copyData.showName}
            //       </Menu.Item>);
            //   }
            // }
            /* 删除按钮 */
            const indexDel = barContent.findIndex(item => item.key === 'BtnDel');
            const delData = button.filter(item => item.sName === 'BtnDel')[0];
            barContent[indexDel] = (
              <Menu.Item
                key={delData.sName}
                disabled
              ><Icon type="delete" />{delData.showName}
              </Menu.Item>);
          } else if (!nextProps.bCheck) {
            const indexExam = barContent.findIndex(item => item.key === 'BtnExamine');
            const examineData = button.filter(item => item.sName === 'BtnExamine')[0];
            if (examineData !== undefined) {
              barContent[indexExam] = (
                <Menu.Item
                  key={examineData.sName}
                ><Icon type="check" />{examineData.showName}
                </Menu.Item>);
            }
            const indexCancel = barContent.findIndex(item => item.key === 'BtnCancelExamine');
            const cancelExamineData = button.filter(item => item.sName === 'BtnCancelExamine')[0];
            if (cancelExamineData !== undefined) {
              barContent[indexCancel] = (
                <Menu.Item
                  key={cancelExamineData.sName}
                  disabled
                ><Icon type="rollback" />{cancelExamineData.showName}
                </Menu.Item>);
            }
            /* 复制到按钮 */
            const indexCopy = barContent.findIndex(item => item.key === 'BtnCopyTo');
            const barContentData = barContent.filter(item => item.key === 'BtnCopyTo')[0];
            if (barContentData !== undefined) {
              const children = barContentData.props.children !== undefined && Array.isArray(barContentData.props.children) ? barContentData.props.children : '';
              const copyData = button.filter(item => item.sName === 'BtnCopyTo')[0];
              if (children !== '') {
                barContent[indexCopy] = (
                  <SubMenu
                    key={copyData.sName}
                    className={styles.toolBarSub}
                    title={<span><Icon type="copy" /><span>{copyData.showName}</span><Icon type="down" theme="outlined" /></span>}
                    // disabled
                  >{children}
                  </SubMenu>);
              } else {
                const { copyToMenu, copyToMenuSelect } = this.state;
                const menuChild = copyToMenu.filter(child => child.sControlName.indexOf(copyToMenuSelect[0].sControlName.substr(copyToMenuSelect[0].sControlName.indexOf('_') + 1)) > 0);
                barContent[indexCopy] = (
                  <Menu.Item
                    key={copyData.sName}
                    data-sactiveid={menuChild.length > 0 ? menuChild[0].sActiveId : ''}
                    data-cfig={menuChild}
                    // disabled
                  ><Icon type="copy" />{copyData.showName}
                  </Menu.Item>);
              }
              /* 删除按钮 */
              const indexDel = barContent.findIndex(item => item.key === 'BtnDel');
              const delData = button.filter(item => item.sName === 'BtnDel')[0];
              barContent[indexDel] = (
                <Menu.Item
                  key={delData.sName}
                ><Icon type="delete" />{delData.showName}
                </Menu.Item>);
            }
          }
        }
        button.forEach((btn) => {
          const btnConfig = commonFunc.getConfig('control', btn.sName, gdsconfigformslave, gdsformconst, gdsjurisdiction, btn.showName);
          if (btn.sName === 'BtnPrint') {
            const child = childButton.filter(item => item.sName.indexOf(`${btn.sName}.`) > -1);
            if (btnConfig.bVisible) {
              if (child.length === 0) {
                barContent.splice(barContent.findIndex(item => item.key === 'BtnPrint'), 1);
                barContent.push(
                  <Menu.Item
                    key={btn.sName}
                  ><Icon type="printer" />{btnConfig.showName}
                  </Menu.Item>);
              } else {
                const btnChild = [];
                child.forEach((item) => {
                  const childConfig = commonFunc.getConfig('control', item.sName, gdsconfigformslave, gdsformconst, gdsjurisdiction, item.showName);
                  if (childConfig.bVisible) {
                    btnChild.push(
                      <Menu.Item
                        key={item.sName}
                        data-sid={item.sId}
                      >{childConfig.showName}
                      </Menu.Item>);
                  }
                });
                barContent.splice(barContent.findIndex(item => item.key === 'BtnPrint'), 1);
                barContent.push(
                  <SubMenu
                    key={btn.sName}
                    title={<span><Icon type="printer" /><span>{btnConfig.showName}</span><Icon type="down" theme="outlined" /></span>}
                    className={styles.toolBarSub}
                  >{btnChild}
                  </SubMenu>);
              }
            }
          }
        });
      } else if (!nextProps.disabled) {
        barContent.forEach((child, i) => {
          if (child.key === 'BtnSave' || child.key === 'BtnCancel') {
            child = {
              ...child,
              props: { ...child.props, disabled: false },
            };
            barContent[i] = { ...child };
          } else {
            child = {
              ...child,
              props: { ...child.props, disabled: true },
            };
            barContent[i] = { ...child };
          }
        });
      }
    }
    this.setState({ barContent });
  }
  /* componentWillReceiveProps(nextProps) {
   const toolConfig = nextProps.mergeTable.tableConfig;
   const { configType, componentName, sDataListTabId } = toolConfig;
   /!* 快捷列表及相对应的标签 *!/
   if (this.state.sTabId === sDataListTabId
   && this.state.sTabId === nextProps.app.sTabId
   && configType === 'tool' && this.state.componentName === componentName) {
   const { route, sMenuName, sActiveId } = toolConfig;
   this.setState({ route });
   if (route !== undefined && sMenuName !== undefined && sActiveId !== undefined) {
   /!* 双击表格，打开新标签页 *!/
   const sTabId = new Date().getTime().toString(); /!* Tab标签Id *!/
   const cName = route.substring(1);
   const url = `${config.server_host}business/getModelBysId/${sActiveId}?
   modelsId=${sActiveId}`; /!* 获取新窗口的窗体配置 *!/
   this.props.onFormHeader(url, sTabId, route, cName, sActiveId); /!* 获取窗体内容配置 *!/
   const pane = { title: sMenuName, key: sTabId, route };
   this.props.onAddPane(pane);
   }
   if (this.state.barContent.length === 0) {
   const { btnData } = this.state;
   const { formData, gdsformconst, gdsjurisdiction } = toolConfig;
   const btnFormConfig = []; /!* 工具栏按钮配置 *!/
   for (const child of formData) {
   for (const slaveChild of child.gdsconfigformslave) {
   if (slaveChild.sName === '' || slaveChild.sName === 'picArr') {
   /!* 取按钮以及跳转窗体Id, sActiveId供增删改用 *!/
   btnFormConfig.push(slaveChild);
   }
   }
   }
   /!* 配置,常量,权限 *!/
   const data = JSON.parse(JSON.stringify(btnData));
   /!* 最终生成的按钮, 把地址传递改给值传递，给的值不变 *!/
   const { bHasJurisdiction } = gdsjurisdiction[0]; /!* 是否有权限配置 *!/
   // const bHasJurisdiction = false;
   let pjList = []; /!* 权限 *!/
   if (bHasJurisdiction) {
   pjList = gdsjurisdiction[0].pjList; /!* 有权限的字段 *!/
   }
   data.forEach((child, i) => {
   const { sName } = child;
   /!* 权限查找 *!/
   const btnListCount = pjList.findIndex(item => item.sName === sName);
   /!* 配置查找 *!/
   const btnConfigCount = btnFormConfig.findIndex(item => item.sControlName === sName);
   /!* 常量查找 *!/
   const btnConstCount = gdsformconst.findIndex(item => item.sName === sName);
   if (btnConstCount >= 0) {
   if (gdsformconst[btnConstCount] !== undefined) {
   data[i].showName = gdsformconst[btnConstCount].showName;
   } else if (btnFormConfig[btnConfigCount] !== undefined) {
   data[i].showName = btnFormConfig[btnConfigCount].showName;
   } else {
   data[i].showName = child.showName;
   }
   }
   if (pjList.length > 0) {
   if (btnListCount >= 0 && btnConfigCount >= 0) {
   data[i].bVisible = pjList[btnListCount].bShow
   && btnFormConfig[btnConfigCount].bVisible;
   } else if (btnListCount >= 0 && btnConfigCount < 0) {
   data[i].bVisible = pjList[btnListCount].bShow;
   } else if (btnListCount < 0 && btnConfigCount > 0) {
   data[i].bVisible = btnFormConfig[btnConfigCount].bVisible;
   } else {
   data[i].bVisible = true;
   }
   } else {
   data[i].bVisible = btnConfigCount >= 0 ? btnFormConfig[btnConfigCount].bVisible : true;
   }
   const obj = btnFormConfig.filter(item => (item.sName === 'picArr'));
   if (obj.length > 0) {
   data[i].sActiveId = obj[0].sActiveId;
   } else {
   data[i].sActiveId = '';
   }
   });
   const barContent = [];
   const btnOperationChild = [];
   data.forEach((child) => {
   if (child.bVisible) {
   if (child.sName === 'BtnInvalid' ||
   child.sName === 'BtnCancelInvalid' ||
   child.sName === 'BtnOut') {
   btnOperationChild.push(
   <Menu.Item key={child.sName} sActiveId={child.sActiveId}>
   {child.showName}
   </Menu.Item>,
   );
   }
   }
   });
   data.forEach((child) => {
   if (child.bVisible) {
   this.componentVisible = true;
   /!* 组件显示 *!/
   if (child.sName !== 'BtnInvalid' &&
   child.sName !== 'BtnCancelInvalid' && child.sName !== 'BtnOut') {
   if (child.sName === 'BtnBsOperation') {
   if (btnOperationChild.length > 0) {
   barContent.push(
   <SubMenu key={child.sName} title={child.showName} sActiveId={child.sActiveId}>
   {btnOperationChild}
   </SubMenu>,
   );
   }
   } else if (child.sName === 'BtnSave') {
   barContent.push(
   <Menu.Item key={child.sName} sActiveId={child.sActiveId}>
   <Button htmlType="submit" onClick={this.props.onSubmit}>
   {child.showName}</Button>
   </Menu.Item>,
   );
   } else {
   barContent.push(
   <Menu.Item key={child.sName} sActiveId={child.sActiveId}>
   {child.showName}
   </Menu.Item>,
   );
   }
   }
   }
   });
   this.setState({ barContent, toolConfig, sGrd: componentName });
   }
   }
   } */

  /* shouldComponentUpdate(nextProps, nextState) {
   const toolConfig = nextProps.mergeTable.tableConfig;
   const { sDataListTabId, componentName } = toolConfig;
   if (nextState.barContent === this.state.barContent) return false;
   return nextState.sTabId === sDataListTabId
   && nextState.sTabId === nextProps.app.sTabId
   && nextState.componentName === componentName;
   } */

  handlePoup = (e, key) => {
    const { sTabId, componentName } = this.state;
    const { panes } = this.props.app;
    if (panes.length > config.maxTabSize) {
      message.error('Tab数量已超过限制，无法新增！');
    }
    const curPane = panes.filter(item => (item.key === sTabId)); /* 本页面pane */
    const sNameList = curPane.route; /* 当前页路由 */
    if (sNameList === '/commonList') {
      const sActiveId = e.item.props['data-sactiveid']; /* 弹出页面的窗体Id */
      if (sActiveId !== '') {
        const sNameUrl = `${config.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}`;
        const value = {
          sActiveId,
          sNameUrl,
          configType: 'tool',
          componentName,
        };
        this.props.onRouteName(value);
      }
    } else if (key === 'BtnUpd') {
      const obj = {
        disabled: false,
      };
      if (this.props.onEdit) {
        this.props.onEdit(obj);
      }
    } else if (key === 'BtnAdd') {
      if (this.props.onAdd) {
        this.props.onAdd();
      }
    }
  };

  handleClick = (e) => {
    const { key } = e;
    if (key === 'BtnRefresh') {
      /* 刷新 */
      // const { toolConfig } = this.state;
      /* const { sGrd } = this.state; /!* 重新给值，字符串值传递，值不会变 *!/
       const componentName = sGrd.substring(4); /!* 去掉此组件表名前缀 *!/
       toolConfig.componentName = componentName; /!* 对象，地址传递，值改变 *!/
       this.props.onRefresh(toolConfig); */
      this.props.onRefresh();
    }
    if (key === 'BtnAdd' || key === 'BtnUpd') {
      /* 新增或编辑 */
      this.handlePoup(e, key);
    }
    if (key === 'BtnSave') {
      if (this.props.onSubmit) {
        this.props.onSubmit();
      }
    }
    if (key === 'BtnCancel') {
      if (this.props.onBtnCancel) {
        this.props.onBtnCancel();
      }
    }
    if (key === 'BtnDel') {
      if (this.props.onBtnDel) {
        this.props.onBtnDel();
      }
    }
    /* 复制到 */
    if (e.keyPath.indexOf('BtnCopyTo') > -1) {
      if (this.props.onCopyTo) {
        this.props.onCopyTo(key, e.item.props['data-sactiveid'], e.item.props['data-cfig']);
      }
    }
    /* 复制从 */
    if (e.keyPath.indexOf('BtnCopyFrom') > -1) {
      if (this.props.onCopyFrom) {
        this.props.onCopyFrom(e.item.props['data-sactiveid'], e.item.props['data-cfig']);
      }
    }
    /* 上查 */
    if (e.keyPath.indexOf('BtnUpCheck') > -1) {
      if (this.props.searchUpDown) {
        this.props.searchUpDown(e.item.props['data-sactiveid'], e.item.props['data-cfig']);
      }
    }
    /* 下查 */
    if (e.keyPath.indexOf('BtnDownCheck') > -1) {
      if (this.props.searchUpDown) {
        this.props.searchUpDown(e.item.props['data-sactiveid'], e.item.props['data-cfig']);
      }
    }
    /* 标准打印 */
    if (key === 'BtnPrint') {
      if (this.props.onBtnPrint) {
        this.props.onBtnPrint();
      }
    }
    if (key.indexOf('BtnPrint.') > -1) {
      if (this.props.onBtnPrintChild) {
        const sId = e.item.props['data-sid'];
        this.props.onBtnPrintChild(sId);
      }
    }
    /* 审核 */
    if (key === 'BtnExamine') {
      if (this.props.onBtnExamine) {
        this.props.onBtnExamine();
      }
    }
    /* 消审 */
    if (key === 'BtnCancelExamine') {
      if (this.props.onBtnCancelExamine) {
        this.props.onBtnCancelExamine();
      }
    }
    /* 作废 */
    if (key === 'BtnBsOperation.BtnInvalid') {
      if (this.props.onBtnInvalid) {
        this.props.onBtnInvalid();
      }
    }
    /* 取消作废 */
    if (key === 'BtnBsOperation.BtnCancelInvalid') {
      if (this.props.onBtnCancelInvalid) {
        this.props.onBtnCancelInvalid();
      }
    }
    /* 下一条 */
    if (key === 'BtnNext') {
      if (this.props.onNext) {
        this.props.onNext();
      }
    }
    /* 上一条 */
    if (key === 'BtnPrior') {
      if (this.props.onBtnPrior) {
        this.props.onBtnPrior();
      }
    }
    /* 首条 */
    if (key === 'BtnFirst') {
      if (this.props.onBtnFirst) {
        this.props.onBtnFirst();
      }
    }
    /* 末条 */
    if (key === 'BtnLast') {
      if (this.props.onBtnLast) {
        this.props.onBtnLast();
      }
    }
    /* 导出Excel */
    if (key === 'BtnOut') {
      if (this.props.onBtnOut) {
        this.props.onBtnOut();
      }
    }
  };
  render() {
    const { barContent } = this.state;
    const barContent1 = [...barContent];
    return (
      <div>
        {
          <Menu
            onClick={this.handleClick}
            mode="horizontal"
            className={styles.toolBar}
          >
            {barContent1}
          </Menu>
        }
        <AffixMenu />
      </div>
    );
  }
}

export default ToolBarComponent;
